import React from 'react';
import { Alert, StyleSheet, Text, View } from 'react-native';
import ImageProcessor from '../utils/ImageProcessor';
import FaceCheck from './FaceCheck';

const FaceDetectionExample: React.FC = () => {
    // 当检测到人脸时的回调函数
    const handleFaceDetected = async (imagePath: string) => {
        try {
            // 创建图片信息
            const imageInfo = await ImageProcessor.getImageInfo(imagePath, 1);
            
            // 显示图片信息
            ImageProcessor.showImageInfo(imageInfo);
        } catch (error) {
            console.error('处理图片失败:', error);
            Alert.alert('处理失败', '无法处理检测到的图片');
        }
    };

    return (
        <View style={styles.container}>
            <View style={styles.header}>
                <Text style={styles.title}>人脸检测</Text>
                <Text style={styles.subtitle}>检测到人脸时自动截图</Text>
            </View>
            
            <FaceCheck
                onFaceDetected={handleFaceDetected}
                detectionInterval={3000}
            />
        </View>
    );
};

const styles = StyleSheet.create({
    container: {
        flex: 1,
        backgroundColor: '#f5f5f5',
    },
    header: {
        padding: 20,
        backgroundColor: '#3b82f6',
        alignItems: 'center',
    },
    title: {
        fontSize: 20,
        fontWeight: 'bold',
        color: 'white',
        marginBottom: 5,
    },
    subtitle: {
        fontSize: 14,
        color: 'rgba(255, 255, 255, 0.8)',
    },
});

export default FaceDetectionExample; 